package com.twu.biblioteca;

import com.twu.biblioteca.Interfaces.MenuOption;
import com.twu.biblioteca.options.CheckMemberShipOption;
import com.twu.biblioteca.options.ListAllBooksOption;
import com.twu.biblioteca.options.ReserveBookOption;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Application {
    private static Application app;

    public static Application getApp() {
        if (app == null) {
            return new Application();
        } else {
            return app;
        }
    }

    public String welcomeMessage() {
        return "Welcome to the LMS";
    }

    public List<String> menuOptions() {
        return Arrays.asList("1. List All the books", "2. Reserve a book", "3. Check membership details", "4. Exit");
    }

    public HashMap<Integer, MenuOption> options = new HashMap<Integer, MenuOption>() {{
        put(1, new ListAllBooksOption());
        put(2, new ReserveBookOption());
        put(3, new CheckMemberShipOption());
    }};

    public MenuOption selectOption(int integerChoice) {
        return this.options.get(integerChoice);
    }

    public Boolean checkForExitInstruction(Boolean running, int integerChoice) {
        if (integerChoice == 4) {
            running = false;
        }
        return running;
    }

    public void execute(MenuOption currentOption) {
        if (currentOption != null) {
            currentOption.run(this);
        }
    }

    private List<Book> books = new ArrayList<Book>() {{
        add(new Book(1, "Oliver Twist"));
        add(new Book(2, "Pride and Prejudice"));
        add(new Book(3, "No Country for Old Men"));
        add(new Book(4, "Dead Country for Old Men", Book.TAKEN));
    }};

    public List<Book> getBooks() {
        return books;
    }
}
